package cn.sharp.bbs.controller;

import cn.sharp.bbs.common.Result;
import cn.sharp.bbs.entity.BO.CurrentUser;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 一些测试类
 */
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * 测试从RequestAttribute中获取CurrentUser
     * @param user RequestAttribute中的用户实体
     * @return 将CurrentUser存入data作为响应发送
     */
    @RequestMapping("/security")
    public Result test(@Nullable @RequestAttribute("CurrentUser") CurrentUser user){
        if(user==null){
            return Result.success("未登录");
        }
        return Result.success(user);
    }
}
